//
//  MullImageModelCell.m
//  Otaku
//
//  Created by lanou3g on 16/5/16.
//  Copyright © 2016年 Liuwx. All rights reserved.
//

#import "MullImageModelCell.h"

@interface MullImageModelCell()
@property (weak, nonatomic) IBOutlet UIImageView *userImageView;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIImageView *bigIamgeView;
 

@end
static CGFloat height = 0;
@implementation MullImageModelCell

- (void)setModel:(MullImageModel *)model {
    _model = model;
    self.userImageView.layer.cornerRadius = 15;
    self.userImageView.layer.masksToBounds = YES;
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:self.model.user[@"avatar_url"]]];
    self.userNameLabel.text = self.model.user[@"name"];
    self.contentLabel.text = self.model.text;
    [self.bigIamgeView sd_setImageWithURL:[NSURL URLWithString:self.model.large_image[@"url_list"][0][@"url"]]];
    
    CGSize maxSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 2 * 10, MAXFLOAT);
    CGFloat textHeight = [self.model.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size.height;
    height = 10 + textHeight + 10;
    
    CGFloat Width = [UIScreen mainScreen].bounds.size.width;
    
    CGFloat h = [self.model.large_image[@"r_height"] floatValue];
    CGFloat w = [self.model.large_image[@"width"] floatValue];
    
    CGFloat ImageHeight = h * Width / w;
    if (h == 0 || w == 0) {
        ImageHeight = 0;
    }
    
    height = ImageHeight + 10;

}

+ (CGFloat)cellHeight {
    return height;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
